package com.javakc.commonutils.api;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName ApiCode
 * @Description 统一数据结果返回
 * @Author xujie
 * @Date 2021/11/3
 * @Version 1.0.0
 **/
@Data
public class APICODE {

    private Integer code;
    private String message;

    private boolean success;

    private Map<String,Object> data = new HashMap<>();

    private APICODE(){

    }

    public static APICODE OK(){
        APICODE apicode = new APICODE();
        apicode.setCode(ResultCode.SUCCESS);
        apicode.setMessage("服务调用成功");
        apicode.setSuccess(true);
        return apicode;
    }

    public static APICODE ERROR(){
        APICODE apicode = new APICODE();
        apicode.setCode(ResultCode.ERROR);
        apicode.setMessage("服务调用失败");
        apicode.setSuccess(false);
        return apicode;
    }

    public APICODE code(Integer code){
        this.code = code;
        return this;
    }

    public APICODE message(String message){
        this.message = message;
        return this;
    }

    public APICODE success(boolean success){
        this.success = success;
        return this;
    }

    public APICODE data(String key ,Object value){
        this.data.put(key,value);
        return this;
    }

    public APICODE data(Map<String,Object> data){
        this.setData(data);
        return this;
    }

}
